home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 9
/
Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO
/
039a
/
netpq203.zip
/
MENUDRVR.C
< prev
next >
Wrap
Text File
|
1993-03-01
|
3KB
|
133 lines
#include <stdio.h>
#include <conio.h>
#include "nos.h"
#include "noslib.h"
#include "netpq.h"
#include "proto.h"
int selection, xbase, ybase;
int menu (char *prompts [], int numberofprompts, int xsize, int x, int y)
{
// displays the prompts in *prompts as a menu and allows the operator
// to select one of the prompts through use of the cursor keys.
int i;
xbase = x;
ybase = y;
selection = 0;
gotoxy (xbase, (ybase++) );
nohighlight ();
cprintf (" ╔");
for (i = 1; i <= xsize; i++)
cprintf ("═");
cprintf ("╗ ");
while (selection < numberofprompts)
{
displayoneprompt (prompts, xsize, false);
selection++;
}
gotoxy (xbase, (ybase + selection) );
cprintf (" ╚");
for (i = 1; i <= xsize; i++)
cprintf ("═");
cprintf ("╝ ");
getchoice (prompts, xsize, numberofprompts);
return selection;
}
int getchoice (char *prompts [], int xsize, int numberofprompts)
{
// handles operator actions
selection = 0;
while (true)
{
displayoneprompt (prompts, xsize, true);
while (kbhit () == 0);
switch (getextch ())
{
case key_home:
displayoneprompt (prompts, xsize, false);
selection = 0;
break;
case key_end:
displayoneprompt (prompts, xsize, false);
selection = numberofprompts - 1;
break;
case key_cursorup:
displayoneprompt (prompts, xsize, false);
do
{
selection--;
if (selection < 0)
selection = numberofprompts - 1;
}
while (strlen (prompts [selection]) == 0);
break;
case key_cursordown:
displayoneprompt (prompts, xsize, false);
do
{
selection++;
if (selection >= numberofprompts)
selection = 0;
}
while (strlen (prompts [selection]) == 0);
break;
case key_esc:
case key_cursorleft:
displayoneprompt (prompts, xsize, false);
selection = -1;
case key_enter:
case key_cursorright:
return (selection);
default:
printf ("\a");
}
}
}
void displayoneprompt (char *prompts [], int xsize, int flag)
{
// displays one prompt string
gotoxy (xbase, (ybase + selection) );
cprintf (" ║");
if (flag == true)
highlight ();
else
nohighlight ();
cprintf ("%-*s", xsize, prompts [selection]);
nohighlight ();
cprintf ("║ ");
gotoxy ( (xbase + 2), (ybase + selection) );
}